home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr33
/
xcode.zip
/
XCODE.C
< prev
next >
Wrap
Text File
|
1993-06-26
|
3KB
|
107 lines
/************************************************************************\
**
** XCODE - File encryption/decryption
** 06/26/93, John C. Howard @ Compudata BBS, NJ,
** ref: David Stafford @ ZNT:COMPSHOPPER Compuserv
**
** Compilation:
** This code was compiled and tested under Ultrix, Linux, RISC\OS,
** MS-C for DOS and a few small C compilers without needing any modification.
**
** Description:
** The key is a 32 bit value giving 2^32 (4,294,967,296) combinations.
** If a code breaking program were to process a 1,000 keys a second testing
** based on an ASCII text file context, decoding would take an average of
** 25 days. If two encryption passes are made using 2 keys, that
** duration would be multiplied by 4 billion.
**
** Passing the encrypted file back through XCODE with the key will produce
** the original file.
**
** Any Suggestions or Comments? Send me mail at Compudata BBS,
** (609) 232-1245 on Conference 21 (C-language).
**
\************************************************************************/
#include <stdio.h>
/* General definitions */
#define MULTIPLIER 0x015A4E35L
#define INCREMENT 1
#define hlp_msg "***** XCODE - File encryption/decryption *****\n\nsyntax... XCODE {key} {in-filename} {out-filename}\n"
/* Global vaiables */
static long RandomSeed;
static FILE * infile, * outfile;
static char * infilename, * outfilename;
/* Close all open files */
void close_all()
{
fclose( infile );
fclose( outfile );
}
/* Print error message, close all files then exit */
void err_exit( msg )
char * msg;
{
fprintf( stdout, "\n%s\n", msg );
close_all();
exit(-1);
}
/* Print help message through error message handler */
void err_help()
{
err_exit( hlp_msg );
}
int GetRandomNumber( range )
int range;
{
RandomSeed = MULTIPLIER * RandomSeed + INCREMENT;
return( RandomSeed % range );
}
/* Encrypt\Decrypt characters */
void XCODE()
{
int ch;
while( ( ch = getc( infile ) ) != EOF )
{
fputc( ch ^ GetRandomNumber( 256 ), outfile );
}
}
/* Open, encrypt\decrypt then close files */
void Supervisor()
{
if( NULL == ( infile = fopen( infilename, "rb" ) ) )
err_exit( "Can't open input file!" );
if( NULL == ( outfile = fopen( outfilename, "wb" ) ) )
err_exit( "Can't open output file!" );
XCODE();
close_all();
}
void main( argc, argv )
int argc; char * argv[];
{
if( argc != 4 )
err_help();
RandomSeed = atol( argv[1] );
infilename = argv[2];
outfilename = argv[3];
Supervisor();
exit(0);
}